﻿using Lrd.Permissions.Core.Entity;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Security.Claims;
using System.Text;

namespace Lrd.Permissions.Identity
{
    public abstract class RoleClaimBase<TRoleKey> : EntityBase<Guid>
            where TRoleKey : IEquatable<TRoleKey>
    {



        /// <summary>
        /// 获取或设置 角色编号
        /// </summary>
        [DisplayName("角色编号")]
        public  TRoleKey RoleId { get; set; }
        /// <summary>
        /// 获取或设置 声明类型
        /// </summary>
        [DisplayName("声明类型")]
        public  string ClaimType { get; set; }

        /// <summary>
        /// 获取或设置 声明值
        /// </summary>
        [DisplayName("声明值")]
        public  string ClaimValue { get; set; }

        /// <summary>
        /// 使用类型和值创建一个声明对象
        /// </summary>
        /// <returns></returns>
        public virtual Claim ToClaim()
        {
            return new Claim(ClaimType, ClaimValue);
        }

        /// <summary>
        /// 使用一个声明对象初始化
        /// </summary>
        /// <param name="other">声明对象</param>
        public virtual void InitializeFromClaim(Claim other)
        {
            ClaimType = other?.Type;
            ClaimValue = other?.Value;
        }
    }
}
